package com.example.wanandroidsdk.http;

import com.example.wanandroidsdk.constants.Constants;
import com.example.wanandroidsdk.utils.LogUtils;

import java.util.HashMap;
import java.util.Map;

public class WanHttpRequest {
    private static final String TAG = "WanHttp";
    public static void getBanner(final  WanHttpRequestCallBack callBack) {
        getHomeBanner(new WanHttpUtils.OnResponseListener() {
            @Override
            public void onResponse(WanAndroidHttpResult httpResult) {
                if (httpResult == null && httpResult.getData() == null) {
                    return;
                }
                String content = httpResult.getData().toString();
                try {
                    if (httpResult.isBizSucceed(true)) {
                        callBack.onResponse(content);
                    } else {
                        String message = httpResult.getMessage();
                        callBack.onFailed(message);
                    }
                    LogUtils.e(TAG, content);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public static void getHotKey(final WanHttpRequestCallBack callBack){
        getHotKey(new WanHttpUtils.OnResponseListener() {
            @Override
            public void onResponse(WanAndroidHttpResult httpResult) {
                String content = httpResult.getData().toString();
                try {
                    if (httpResult.isBizSucceed(true)) {
                        callBack.onResponse(content);
                    } else {
                        String message = httpResult.getMessage();
                        callBack.onFailed(message);
                    }
                    LogUtils.e(TAG, content);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 发送验证码接口
     *
     * @param responseListener
     * @return
     */
    private static WanHttpUtils.RequestThread getHomeBanner(WanHttpUtils.OnResponseListener responseListener) {
        if (responseListener == null) {
            return null;
        }
        Map<String, String> params = new HashMap<>();
        String url = Constants.BASE_URL + Constants.BANNER_LIST;
        params.put("url", url);
        params.put("Method", "GET");
        WanHttpUtils.RequestThread requestThread = new WanHttpUtils.RequestThread(params, responseListener);
        requestThread.start();
        return requestThread;
    }

    private static WanHttpUtils.RequestThread getHotKey(WanHttpUtils.OnResponseListener responseListener){
        if (responseListener == null) {
            return null;
        }
        Map<String, String> params = new HashMap<>();
        String url = Constants.BASE_URL + Constants.HOT_KEY;
        params.put("url", url);
        params.put("Method", "GET");
        WanHttpUtils.RequestThread requestThread = new WanHttpUtils.RequestThread(params, responseListener);
        requestThread.start();
        return requestThread;
    }


}
